package edu.hcmus.sow.domain;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAclEntryByAceOrder", query = "select myAclEntry from AclEntry myAclEntry where myAclEntry.aceOrder = ?1"),
		@NamedQuery(name = "findAclEntryByAuditFailure", query = "select myAclEntry from AclEntry myAclEntry where myAclEntry.auditFailure = ?1"),
		@NamedQuery(name = "findAclEntryByAuditSuccess", query = "select myAclEntry from AclEntry myAclEntry where myAclEntry.auditSuccess = ?1"),
		@NamedQuery(name = "findAclEntryByGranting", query = "select myAclEntry from AclEntry myAclEntry where myAclEntry.granting = ?1"),
		@NamedQuery(name = "findAclEntryById", query = "select myAclEntry from AclEntry myAclEntry where myAclEntry.id = ?1"),
		@NamedQuery(name = "findAclEntryByMask", query = "select myAclEntry from AclEntry myAclEntry where myAclEntry.mask = ?1"),
		@NamedQuery(name = "findAclEntryByPrimaryKey", query = "select myAclEntry from AclEntry myAclEntry where myAclEntry.id = ?1"),
		@NamedQuery(name = "findAllAclEntrys", query = "select myAclEntry from AclEntry myAclEntry") })
@Table(catalog = "sow", name = "acl_entry")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "AclEntry")
public class AclEntry implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "ACE_ORDER", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer aceOrder;
	/**
	 */

	@Column(name = "MASK", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer mask;
	/**
	 */

	@Column(name = "GRANTING", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Boolean granting;
	/**
	 */

	@Column(name = "AUDIT_SUCCESS", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Boolean auditSuccess;
	/**
	 */

	@Column(name = "AUDIT_FAILURE", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Boolean auditFailure;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "ACL_OBJECT_IDENTITY", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	AclObjectIdentity aclObjectIdentity;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "SID", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	AclSid aclSid;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setAceOrder(Integer aceOrder) {
		this.aceOrder = aceOrder;
	}

	/**
	 */
	public Integer getAceOrder() {
		return this.aceOrder;
	}

	/**
	 */
	public void setMask(Integer mask) {
		this.mask = mask;
	}

	/**
	 */
	public Integer getMask() {
		return this.mask;
	}

	/**
	 */
	public void setGranting(Boolean granting) {
		this.granting = granting;
	}

	/**
	 */
	public Boolean getGranting() {
		return this.granting;
	}

	/**
	 */
	public void setAuditSuccess(Boolean auditSuccess) {
		this.auditSuccess = auditSuccess;
	}

	/**
	 */
	public Boolean getAuditSuccess() {
		return this.auditSuccess;
	}

	/**
	 */
	public void setAuditFailure(Boolean auditFailure) {
		this.auditFailure = auditFailure;
	}

	/**
	 */
	public Boolean getAuditFailure() {
		return this.auditFailure;
	}

	/**
	 */
	public void setAclObjectIdentity(AclObjectIdentity aclObjectIdentity) {
		this.aclObjectIdentity = aclObjectIdentity;
	}

	/**
	 */
	@JsonIgnore
	public AclObjectIdentity getAclObjectIdentity() {
		return aclObjectIdentity;
	}

	/**
	 */
	public void setAclSid(AclSid aclSid) {
		this.aclSid = aclSid;
	}

	/**
	 */
	@JsonIgnore
	public AclSid getAclSid() {
		return aclSid;
	}

	/**
	 */
	public AclEntry() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(AclEntry that) {
		setId(that.getId());
		setAceOrder(that.getAceOrder());
		setMask(that.getMask());
		setGranting(that.getGranting());
		setAuditSuccess(that.getAuditSuccess());
		setAuditFailure(that.getAuditFailure());
		setAclObjectIdentity(that.getAclObjectIdentity());
		setAclSid(that.getAclSid());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("aceOrder=[").append(aceOrder).append("] ");
		buffer.append("mask=[").append(mask).append("] ");
		buffer.append("granting=[").append(granting).append("] ");
		buffer.append("auditSuccess=[").append(auditSuccess).append("] ");
		buffer.append("auditFailure=[").append(auditFailure).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof AclEntry))
			return false;
		AclEntry equalCheck = (AclEntry) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
